package com.javademo.multithreadingtest;

import lombok.extern.slf4j.Slf4j;

import java.time.LocalTime;

public class TimerThreadTest {
    public static void main(String[] args) throws InterruptedException {
        Thread timeTread = new TimerThread();
        Thread testThread = new MyTestThread();
        timeTread.setDaemon(true);
        timeTread.start();
        testThread.start();
        testThread.join();
    }
}

@Slf4j
class TimerThread extends Thread{
    @Override
    public void run() {
        while (true){
            log.info(String.valueOf(LocalTime.now()));
            try {
                Thread.sleep(1000);
            }catch (InterruptedException e){
                log.error("error:{}", e.getMessage(), e);
            }
        }
    }
}

@Slf4j
class MyTestThread extends Thread{
    int sum = 0;
    @Override
    public void run() {
        while (sum < 20){
            sum++;
            log.info("sum:{}", sum);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                log.error("error:{}", e.getMessage(), e);
            }
        }
    }
}